package com.xpffly.design.proxy.force.service.impl;

import com.xpffly.design.proxy.force.service.GamePlayer;

/**
 * @Author: xpengfei
 * @Date: 2021/3/30 22:00
 * @Description：强制代理的真实角色
 */
public class GamePlayerReal implements GamePlayer {

    private String name = "";
    /**
     * 代理
     */
    private GamePlayer gamePlayerProxy = null;


    public GamePlayerReal(String name) {
        this.name = name;
    }

    public void login(String user, String password) {
        if (this.isProxy()) {
            System.out.println("登录名为"+user+"的用户 "+this.name + "登录成功...");
        } else {
            System.out.println("请使用指定的代理访问...");
        }
    }

    public void killBoss() {
        if (this.isProxy()) {
            System.out.println(this.name + "正在打怪...");
        } else {
            System.out.println("请使用指定的代理访问...");
        }
    }

    public void upgrade() {
        if (this.isProxy()) {
            System.out.println(this.name + "升级啦...");
        } else {
            System.out.println("请使用指定的代理访问...");
        }
    }

    public GamePlayer getGamePlayerProxy() {
        // 指定自己的代理（创建）
        this.gamePlayerProxy = new GamePlayerProxy(this);
        return this.gamePlayerProxy;
    }

    /**
     * 校验是否代理访问
     *
     * @return
     */
    private boolean isProxy() {
        if (this.gamePlayerProxy == null) {
            return false;
        }
        return true;
    }
}
